package com.hdmall.business.common.util;

public class SimilarUtil {

    public static int similarValue(String name1, String name2){

        String []subName1 = name1.split(",", -1);
        String []subName2 = name2.split(",", -1);

        //相似度计算公式 = 属性*30+光泽*20+纤度孔数*20+单合股*10+颜色*10+形状*10
        int []arr = new int [7];
        int []brr = new int [7];
        arr[0] = 0;brr[0] = 30;
        arr[1] = 1;brr[1] = 20;
        arr[2] = 3;brr[2] = 20;
        arr[3] = 5;brr[3] = 10;
        arr[4] = 6;brr[4] = 10;
        arr[5] = 7;brr[5] = 10;


        int result = 0;
        for(int i = 0; i <= 5; i++){
            if((null != subName1[arr[i]] && "".equals(subName1[arr[i]]) == false) && (null != subName2[arr[i]] && "".equals(subName2[arr[i]]) == false)){
                result += brr[i] * (subName1[arr[i]].equals(subName2[arr[i]])?1:0);
            }

        }
        return  result;
    }


}
